﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

using C4F.DevKit.Bluetooth.ServiceAndDeviceDiscovery;

namespace Jarvis.Sensors
{
    class BluetoothSensor : Sensor
    {
        public BluetoothSensor() :
            base(10000)
        {
            this.name = "Bluetooth Devices";
        }

        public override void Sense(object stateInfo)
        {
            try
            {
                BluetoothDeviceServicesManager manager = new BluetoothDeviceServicesManager();

                List<Device> devices = manager.DiscoverAllDevices();

                List<object> readings = new List<object>();

                foreach (Device d in devices)
                    readings.Add(d.Name + " (" + d.Address.Address + ")");

                if (readings.Count < 1)
                    readings = null;

                this.log(readings);
            }
            catch (Exception)
            {
                this.log(null);
            }
        }
    }
}
